/**
 * ©2013-2015 Alan L. Rights Reserved.
 */
package org.freedom.railhunter.service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.codehaus.jackson.JsonNode;
import org.freedom.railhunter.model.LeftTicketItem;
import org.freedom.railhunter.model.Passenger;
import org.freedom.railhunter.model.Order;
import org.freedom.railhunter.model.QueryLeftNewDTO;
import org.freedom.railhunter.model.QueueCount;
import org.freedom.railhunter.model.SeatType;
import org.freedom.railhunter.model.SubmitOrderResult;
import static org.freedom.railhunter.service.BaseService.DATA;
import static org.freedom.railhunter.service.BaseService.JSON_ATTR;
import static org.freedom.railhunter.service.BaseService.STATUS;
import static org.freedom.railhunter.service.BaseService.object_mapper;
import org.freedom.railhunter.util.HttpConnectionManager;
import org.freedom.railhunter.config.PathConfig;
import org.freedom.railhunter.exception.SessionExpiredException;
import org.freedom.railhunter.exception.SubmitFailedException;
import org.freedom.railhunter.model.AcceptDataType;
import static org.freedom.railhunter.service.BaseService.JSON_ATTR;
import static org.freedom.railhunter.service.BaseService.PURPOSE_CODES;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Alan
 */
public class TicketService extends BaseService {
    
    private static final Logger logger = LoggerFactory.getLogger(TicketService.class);
    
    private static final SimpleDateFormat gmt_format = new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss", Locale.ENGLISH);
    static {
        gmt_format.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
    }

    public static final String QUERY_LEFT_NEW_DTO = "queryLeftNewDTO";
    
    public static final String SUBMIT_STATUS = "submitStatus";
    
    public static final String IS_RELOGIN = "isRelogin";
    
    // 自动提交订单参数
    public static final String BED_LEVEL_ORDER_NUM = "bed_level_order_num";
    public static final String BED_LEVEL_ORDER_NUM_VALUE = "000000000000000000000000000000";
    public static final String CANCEL_FLAG = "cancel_flag";
    public static final String CANCEL_FLAG_VALUE = "2";
    public static final String OLD_PASSENGER_STR = "oldPassengerStr";
    public static final String PASSENGER_TICKET_STR = "passengerTicketStr";
    public static final String QUERY_FROM_STATION_NAME = "query_from_station_name";
    public static final String QUERY_TO_STATION_NAME = "query_to_station_name";
    public static final String SECRET_STR = "secretStr";
    public static final String TOUR_FLAG = "tour_flag";
    public static final String TOUR_FLAG_VALUE = "dc";
    
    // 查询队列数量参数
    public static final String REPEAT_SUBMIT_TOKEN = "REPEAT_SUBMIT_TOKEN";
    public static final String FROM_STATION_TELECODE = "fromStationTelecode";
    public static final String LEFT_TICKET = "leftTicket";
    public static final String LEFT_TICKET_STR = "leftTicketStr";
    public static final String SEAT_TYPE = "seatType";
    public static final String STATION_TRAIN_CODE = "stationTrainCode";
    public static final String TO_STATION_TELECODE = "toStationTelecode";
    public static final String TRAIN_NO = "train_no";
    
    // 确认订单参数
    public static final String KEY_CHECK_ISCHANGE = "key_check_isChange";
    public static final String TRAIN_LOCATION = "train_location";
    
    private static final String PARAMETER_SEPARATOR = "&";
    private static final String NAME_VALUE_SEPARATOR = "=";
    
     private static TicketService  ticketService;
    
    private TicketService() {
    }
    
    public static TicketService getInstance() {
        if (ticketService == null) {
            ticketService = new TicketService();
        }
        return ticketService;
    }
    
    /**
     * 查询余票
     * 
     * @param tranDate
     * @param fromStationCode
     * @param toStationCode
     * @param purposeCodes
     * @param cookieData 
     */
    public LeftTicketItem[] queryLeftTicket(Date trainDate, String fromStationCode, String toStationCode,
            String purposeCodes, Map<String, String> cookieData) {
        try {
            String result = HttpConnectionManager.getHttpRequestAsString(
                    PathConfig.LEFT_TICKET_QUERY_PATH
                    + "?leftTicketDTO.train_date=" + yyyy_mm_dd_format.format(trainDate)
                    + "&leftTicketDTO.from_station=" + fromStationCode
                    + "&leftTicketDTO.to_station=" + toStationCode
                    + "&purpose_codes=" + purposeCodes,
                    PathConfig.LEFT_TICKET_INIT_PATH,
                    null,
                    cookieData);
            JsonNode root = object_mapper.readTree(json_factory.createJsonParser(result));
            JsonNode dataNode = root.get(DATA);
            if (dataNode == null) {
                logger.warn("没有查询到余票！");
                return new LeftTicketItem[]{};
            }
            return object_mapper.readValue(dataNode, LeftTicketItem[].class);
        } catch (IOException e) {
            logger.error("查询余票异常", e);
            return new LeftTicketItem[]{};
        }
    }
    
    /**
     * 自动选择车票并创建订单
     * 
     * @param leftTicketItems 余票
     * @param passengers 联系人
     * @param trainCodes 车次（列车代码）集合
     * @param seatTypes 席别集合
     * @param isTrainHighPriority 是否车次优先（true:车次优先， false:席别优先）
     * @param trainDate 日期
     * String purposeCodes 成人票或在学生票（ADULT：成人票，0X00：学生票）
     * @return 
     */
    public Order createOrder(LinkedList<LeftTicketItem> leftTicketItems,  List<Passenger> passengers, 
            List<String> trainCodes, List<SeatType> seatTypes, Date trainDate, String purposeCodes, 
            final boolean isTrainHighPriority) {
        
        for (LeftTicketItem item : leftTicketItems) {
            
            // 没有车次和席别自动按票数量选择
            if (trainCodes == null || trainCodes.isEmpty()) {
                if (seatTypes == null || seatTypes.isEmpty()) {
                    SeatType seatType = item.getQueryLeftNewDTO().getSeatTypeNumberMoreThan(passengers.size());
                    if (seatType != null) {
                        Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                        logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                + ", seatType: " + order.getSeatType()
                                + ", secretStr: " + order.getLeftTicketItem().getSecretStr());
                        return order;
                    }
                }
            }
            
            if (isTrainHighPriority) {
                // 车次优先
                if (trainCodes == null || trainCodes.isEmpty()) {
                    // 按席别选择
                    for (SeatType seatType : seatTypes) {
                        if (item.getQueryLeftNewDTO().isSeatNumberMoreThan(seatType.getMark(), passengers.size())) {
                            Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                            logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                    + ", seatType: " + order.getSeatType()
                                    + ", secretStr: " + order.getLeftTicketItem().getSecretStr());
                            return order;
                        }
                    }
                } else {
                    for (String trainCode : trainCodes) {
                        if (trainCode.equals(item.getQueryLeftNewDTO().getStationTrainCode())) {
                            if (seatTypes == null || seatTypes.isEmpty()) {
                                // 按车次再按票数来选择
                                SeatType seatType = item.getQueryLeftNewDTO().getSeatTypeNumberMoreThan(passengers.size());
                                if (seatType != null) {
                                    Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                                    logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                            + ", seatType: " + order.getSeatType()
                                            + ", secretStr: " + order.getLeftTicketItem().getSecretStr());
                                    return order;
                                }
                            } else {
                                //按车次再按席别选择
                                for (SeatType seatType : seatTypes) {
                                    if (item.getQueryLeftNewDTO().isSeatNumberMoreThan(seatType.getMark(), passengers.size())) {
                                        Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                                        logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                                + ", seatType: " + order.getSeatType()
                                                + ", secretStr: " + order.getLeftTicketItem().getSecretStr());
                                        return order;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                // 席别优先
                if (seatTypes == null || seatTypes.isEmpty()) {
                    // 按车次再按数量选择
                    for (String trainCode : trainCodes) {
                        if (trainCode.equals(item.getQueryLeftNewDTO().getStationTrainCode())) {
                            SeatType seatType = item.getQueryLeftNewDTO().getSeatTypeNumberMoreThan(passengers.size());
                            if (seatType != null) {
                                Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                                logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                        + "secretStr: " + order.getLeftTicketItem().getSecretStr());
                                return order;
                            }
                        }
                    }
                } else {
                    for (SeatType seatType : seatTypes) {
                        if (item.getQueryLeftNewDTO().isSeatNumberMoreThan(seatType.getMark(), passengers.size())) {
                            if (trainCodes == null || trainCodes.isEmpty()) {
                                // 按席别选择
                                Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                                logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                        + "secretStr: " + order.getLeftTicketItem().getSecretStr());
                                return order;
                            } else {
                                // 先按席别再按车次来选择
                                for (String trainCode : trainCodes) {
                                    if (trainCode.equals(item.getQueryLeftNewDTO().getStationTrainCode())) {
                                        Order order = new Order(item, passengers, seatType, purposeCodes, trainDate);
                                        logger.info("Choose train code: " + order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()
                                                + "secretStr: " + order.getLeftTicketItem().getSecretStr());
                                        return order;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //logger.info("No trains can be choosed!");
        return null;
    }
    
    /**
     * 自动提交订单
     * 
     */
    public SubmitOrderResult autoSubmitOrderRequest(Order order, String queryFromStationName, String queryToStationName, 
            Map<String, String> cookieData) throws SessionExpiredException, SubmitFailedException {
        try {
            List<NameValuePair> parameters = new ArrayList<>();
            parameters.add(new BasicNameValuePair(SECRET_STR, order.getLeftTicketItem().getSecretStr()));
            parameters.add(new BasicNameValuePair(TRAIN_DATE, yyyy_mm_dd_format.format(order.getTrainDate())));
            parameters.add(new BasicNameValuePair(TOUR_FLAG, TOUR_FLAG_VALUE));
            parameters.add(new BasicNameValuePair(PURPOSE_CODES, order.getPurposeCodes()));
            parameters.add(new BasicNameValuePair(QUERY_FROM_STATION_NAME, queryFromStationName));
            parameters.add(new BasicNameValuePair(QUERY_TO_STATION_NAME, queryToStationName));
            parameters.add(new BasicNameValuePair(CANCEL_FLAG, CANCEL_FLAG_VALUE));
            parameters.add(new BasicNameValuePair(BED_LEVEL_ORDER_NUM, BED_LEVEL_ORDER_NUM_VALUE));
            parameters.add(new BasicNameValuePair(PASSENGER_TICKET_STR, order.getPassengerTicketStr()));
            parameters.add(new BasicNameValuePair(OLD_PASSENGER_STR, order.getOldPassengerStr()));
            
            String result = HttpConnectionManager.postHttpRequestAsString(PathConfig.AUTO_SUBMIT_ORDER_REQUEST_PATH,
                    PathConfig.LEFT_TICKET_INIT_PATH, AcceptDataType.All, parameters, formatWithoutEncoding(parameters), cookieData);
            JsonNode root = object_mapper.readTree(json_factory.createJsonParser(result));
            JsonNode statusNode = root.get(STATUS);
            if (statusNode != null && statusNode.getBooleanValue()) {
                JsonNode dataNode = root.get(DATA);
                if (dataNode != null) {
                    JsonNode submitStatusNode = dataNode.get(SUBMIT_STATUS);
                    if (submitStatusNode != null && submitStatusNode.getBooleanValue()) {
                        SubmitOrderResult submitOrderResult = object_mapper.readValue(dataNode, SubmitOrderResult.class);
                        submitOrderResult.decomposeResult();
                        return submitOrderResult;
                    } else {
                        JsonNode isReloginNode = dataNode.get(IS_RELOGIN);
                        if (isReloginNode != null && isReloginNode.getBooleanValue()) {
                            throw new SessionExpiredException("需要重新登录！");
                        }
                    }
                }
            } else {
                JsonNode messageNode = root.get(MESSAGE);
                if  (messageNode != null) {
                    throw new SubmitFailedException(messageNode.toString());
                }
            }
        } catch (IOException e) {
            logger.error("自动提交订单异常", e);
        }
        return new SubmitOrderResult();
    }
    
    private static String formatWithoutEncoding(final List<? extends NameValuePair> parameters) {
        final StringBuilder result = new StringBuilder();
        for (final NameValuePair parameter : parameters) {
            final String pName = parameter.getName();
            final String value = parameter.getValue();
            final String pValue = value != null ? value : "";
            if (result.length() > 0) {
                result.append(PARAMETER_SEPARATOR);
                if (CANCEL_FLAG.equals(pName)) {
                    result.append(PARAMETER_SEPARATOR);
                }
            }
            result.append(pName);
            result.append(NAME_VALUE_SEPARATOR);
            result.append(pValue);
        }
        return result.toString();
    }
    
//    public String getGlobalRepeatSubmitToken(Map<String, String> cookieData) throws CommunicationException {
//        List<NameValuePair> parameters = new ArrayList<>();
//        parameters.add(new BasicNameValuePair("_json_att", ""));
//        try {
//            String result = HttpConnectionManager.postHttpRequestAsString(PathConfig.CONFIRM_PASSENGER_INITWC_PATH,
//                        PathConfig.LEFT_TICKET_INIT_PATH, AcceptDataType.All, parameters, formatWithoutEncoding(parameters), cookieData);
//            Pattern p = Pattern.compile("var globalRepeatSubmitToken = '.+'");
//            Matcher m = p.matcher(result);
//            if (m.find()) {
//                String line = m.group();
//                if (StringUtils.isNotBlank(line)) {
//                    String repeatToken = line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"));
//                    if (StringUtils.isNotBlank(repeatToken)) {
//                        return repeatToken;
//                    }
//                }
//            }
//        } catch (IOException ex) {
//            throw new CommunicationException("获取REPEAT_TOKEN异常", ex);
//        }
//        return "";
//    }
    
    /**
     * 查询队列数量
     * 
     * @param order
     * @param submitOrderResult
     * @param cookieData 
     */
    public QueueCount getQueueCount(Order order, SubmitOrderResult submitOrderResult, 
            Map<String, String> cookieData, String repeatSubmitToken) throws SessionExpiredException {
        try {
            boolean hasFixedSeatType = false;
            // 修正无座的席别为硬座或者二等座
            if (order.getSeatType() == SeatType.WU_ZUO) {
                if (!QueryLeftNewDTO.DOUBLE_DASH.equals(order.getLeftTicketItem().getQueryLeftNewDTO().getYzNum())) {
                    // ticket info 是否要修正？
                    order.setSeatType(SeatType.YING_ZUO);
                    hasFixedSeatType = true;
                } else if (!QueryLeftNewDTO.DOUBLE_DASH.equals(order.getLeftTicketItem().getQueryLeftNewDTO().getZeNum())) {
                    // ticket info 是否要修正？
                    order.setSeatType(SeatType.ER_DENG_ZUO);
                    hasFixedSeatType = true;
                }
            }
            
            List<NameValuePair> parameters = new ArrayList<>();
            parameters.add(new BasicNameValuePair(JSON_ATTR, ""));
            parameters.add(new BasicNameValuePair(FROM_STATION_TELECODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getFromStationTelecode()));
            parameters.add(new BasicNameValuePair(LEFT_TICKET, submitOrderResult.getLeftTicketStr()));
            parameters.add(new BasicNameValuePair(PURPOSE_CODES, order.getPurposeCodes()));
            parameters.add(new BasicNameValuePair(REPEAT_SUBMIT_TOKEN, repeatSubmitToken));
            parameters.add(new BasicNameValuePair(SEAT_TYPE, order.getSeatType().getValue()));
            parameters.add(new BasicNameValuePair(STATION_TRAIN_CODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()));
            parameters.add(new BasicNameValuePair(TO_STATION_TELECODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getToStationTelecode()));
            parameters.add(new BasicNameValuePair(TRAIN_DATE, gmt_format.format(order.getTrainDate()) + " GMT+0800"));
            parameters.add(new BasicNameValuePair(TRAIN_NO, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getTrainNo()));
            
            String result = HttpConnectionManager.postHttpRequestAsString(PathConfig.GET_QUEUE_COUNT_ASYNC_PATH,
                    PathConfig.LEFT_TICKET_INIT_PATH, AcceptDataType.All, parameters, cookieData);
            JsonNode root = object_mapper.readTree(json_factory.createJsonParser(result));
            JsonNode statusNode = root.get(STATUS);
            if (statusNode != null && statusNode.getBooleanValue()) {
                JsonNode dataNode = root.get(DATA);
                if (dataNode != null) {
                    JsonNode isReloginNode = dataNode.get(IS_RELOGIN);
                    if (isReloginNode != null && isReloginNode.getBooleanValue()) {
                        // session失效，需要重新登录
                        throw new SessionExpiredException("需要重新登录！");
                    }
                    
                    QueueCount queueCount = object_mapper.readValue(dataNode, QueueCount.class);
                    if (queueCount != null) {
                        // 解码
                        queueCount.decomposeTicketStr(order.getSeatType().getValue(), hasFixedSeatType);
                        logger.info(queueCount.getMessage());
                        return queueCount;
                    }
                }
            }
        } catch(IOException e) {
            logger.error("查询队列数量异常", e);
        } 
        return null;
    }

    /**
     * 查询队列数量
     * 
     * @param order
     * @param submitOrderResult
     * @param cookieData 
     */
    public QueueCount getQueueCountAsync(Order order, SubmitOrderResult submitOrderResult, 
            Map<String, String> cookieData) throws SessionExpiredException {
        try {
            boolean hasFixedSeatType = false;
            // 修正无座的席别为硬座或者二等座
            if (order.getSeatType() == SeatType.WU_ZUO) {
                if (!QueryLeftNewDTO.DOUBLE_DASH.equals(order.getLeftTicketItem().getQueryLeftNewDTO().getYzNum())) {
                    // ticket info 是否要修正？
                    order.setSeatType(SeatType.YING_ZUO);
                    hasFixedSeatType = true;
                } else if (!QueryLeftNewDTO.DOUBLE_DASH.equals(order.getLeftTicketItem().getQueryLeftNewDTO().getZeNum())) {
                    // ticket info 是否要修正？
                    order.setSeatType(SeatType.ER_DENG_ZUO);
                    hasFixedSeatType = true;
                }
            }
            
            List<NameValuePair> parameters = new ArrayList<>();
            parameters.add(new BasicNameValuePair(JSON_ATTR, ""));
            parameters.add(new BasicNameValuePair(FROM_STATION_TELECODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getFromStationTelecode()));
            parameters.add(new BasicNameValuePair(LEFT_TICKET, submitOrderResult.getLeftTicketStr()));
            parameters.add(new BasicNameValuePair(PURPOSE_CODES, order.getPurposeCodes()));
            parameters.add(new BasicNameValuePair(SEAT_TYPE, order.getSeatType().getValue()));
            parameters.add(new BasicNameValuePair(STATION_TRAIN_CODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getStationTrainCode()));
            parameters.add(new BasicNameValuePair(TO_STATION_TELECODE, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getToStationTelecode()));
            parameters.add(new BasicNameValuePair(TRAIN_DATE, gmt_format.format(order.getTrainDate()) + " GMT+0800"));
            parameters.add(new BasicNameValuePair(TRAIN_NO, 
                    order.getLeftTicketItem().getQueryLeftNewDTO().getTrainNo()));
            
            String result = HttpConnectionManager.postHttpRequestAsString(PathConfig.GET_QUEUE_COUNT_ASYNC_PATH,
                    PathConfig.LEFT_TICKET_INIT_PATH, AcceptDataType.All, parameters, cookieData);
            JsonNode root = object_mapper.readTree(json_factory.createJsonParser(result));
            JsonNode statusNode = root.get(STATUS);
            if (statusNode != null && statusNode.getBooleanValue()) {
                JsonNode dataNode = root.get(DATA);
                if (dataNode != null) {
                    JsonNode isReloginNode = dataNode.get(IS_RELOGIN);
                    if (isReloginNode != null && isReloginNode.getBooleanValue()) {
                        // session失效，需要重新登录
                        throw new SessionExpiredException("需要重新登录！");
                    }
                    
                    QueueCount queueCount = object_mapper.readValue(dataNode, QueueCount.class);
                    if (queueCount != null) {
                        // 解码
                        queueCount.decomposeTicketStr(order.getSeatType().getValue(), hasFixedSeatType);
                        logger.info(queueCount.getMessage());
                        return queueCount;
                    }
                }
            }
        } catch(IOException e) {
            logger.error("查询队列数量异常", e);
        } 
        return null;
    }
    
    /**
     * 确认订单
     * 
     * @param order
     * @param submitOrderResult
     * @param randCode
     * @param cookieData
     * @return 
     */
    public boolean confirmSingleForQueueAsys(Order order, SubmitOrderResult submitOrderResult, 
            String randCode, Map<String, String> cookieData) {
        try {
            List<NameValuePair> parameters = new ArrayList<>();
            parameters.add(new BasicNameValuePair(JSON_ATTR, ""));
            parameters.add(new BasicNameValuePair(KEY_CHECK_ISCHANGE, submitOrderResult.getMd5Str()));
            parameters.add(new BasicNameValuePair(LEFT_TICKET_STR, submitOrderResult.getLeftTicketStr()));
            parameters.add(new BasicNameValuePair(OLD_PASSENGER_STR, order.getOldPassengerStr()));
            parameters.add(new BasicNameValuePair(PASSENGER_TICKET_STR, order.getPassengerTicketStr()));
            parameters.add(new BasicNameValuePair(PURPOSE_CODES, order.getPurposeCodes()));
            parameters.add(new BasicNameValuePair(RAND_CODE, randCode));
            parameters.add(new BasicNameValuePair(TRAIN_LOCATION, submitOrderResult.getLocation_code()));
            
            String result = HttpConnectionManager.postHttpRequestAsString(PathConfig.CONFIRM_SINGLE_FOR_QUEUE_ASYS_PATH,
                    PathConfig.LEFT_TICKET_INIT_PATH, AcceptDataType.JSON, parameters, cookieData);
            JsonNode root = object_mapper.readTree(json_factory.createJsonParser(result));
            JsonNode statusNode = root.get(STATUS);
            if (statusNode != null && statusNode.getBooleanValue()) {
                JsonNode dataNode = root.get(DATA);
                if (dataNode != null) {
                    JsonNode submitStatusNode = dataNode.get(SUBMIT_STATUS);
                    return submitStatusNode != null && submitStatusNode.getBooleanValue();
                }
            }
        } catch(IOException e) {
            logger.error("确认订单异常", e);
        }
        return false;
    }
}
